
import { mapState } from 'vuex'
export default {
  name: 'ChangeCity',
  data() {
    return {
      searchHistory: [],
      /** 搜索记录 */
      searchRecordTwo: {},
      listOne: [],
      listTwo: [],
      listThree: []
    }
  },
  computed: {
    ...mapState(['username'])
  },
  mounted() {
    this.getInformation()
  },
  methods: {
    /** 登出 */
    async logout() {
      let res = await this.$api.logout()
      let { msg } = res
      this.clearUserInfomation()
      sessionStorage.clear()
      this.messageTips('success', msg)
    },
    /** 获取搜索历史数据 */
    async getSearchHistoryList() {
      let resThree = await this.$api.searchRecordHistory({ username: this.username })
      resThree.result ? 
        this.searchHistory = resThree.result.searchHistory :
        this.searchHistory = []
    },
    /** 获取后台数据 */
    async getInformation() {
      let res = await this.$api.main()
      let data = res.data[1]
      this.searchRecordTwo = res.data[2]
      this.listOne = data.listOne
      this.listTwo = data.listTwo
      this.listThree = data.listThree
    },
    /** 搜索 */
    async search(content) {
      await this.$api.addRecord({username: this.username, content})
    },
    /** 删除搜索历史 */
    async deleteSearchHistory() {
      await this.$api.deleteSearchHistory(this.username)
    },
    /** 在聚焦的时候去请求搜索历史数据 */
    inputFocus() {
      this.getSearchHistoryList()
    },
  }
}